import Vue from 'vue'
import Vuex from 'vuex'

import poster from './module/poster.js'
import news from './module/news.js'

Vue.use(Vuex)
let add = uni.getStorageSync('addressList') || {
	city: '',
	province: '',
	district: '',
	lon: 104.066,
	lat: 30.6595,
	postalCode: 0
}
// console.log(add,'123123123')
const store = new Vuex.Store({

	state: {
		scroll: false,
		carNum: 0, //爱车数量
		lon: add.lon, //经度
		lat: add.lat,
		postalCode: add.postalCode, //id
		province: add.province,
		city: add.city, //城市
		district: add.district, //区
		model: {}, //登录信息
		imei: '', //设备信息
		couponInfo: {}, // 优惠券详情信息
		timUserInfo: {}, // tim用户信息
		userinfo: null, // 用户信息
		currentLocation: {}, // 当前位置信息
		isLogin: false,
		isSDKReady: false, // TIM SDK 是否 ready
		massTempData: [], // 群发临时数据
		maintenanceOrderInfo: [], // 保养订单信息
		maintenanceCategory: null, // 智能保养需要的类目
		queueInfo: null, // 排队信息
		maintenanceOrder: null, // 保养订单 用于选择优惠券
		myLoveCar: null, // 我的爱车
		changeIndex: 0, //首页及门店tabs下标
		purchaseChannel: false, // 是否通过扫码进入自助洗车
		isConnectSocket: false, //是否已链接socket
		serviceNumber: {
			number: '4008205656',
			showNumber: '400-820-5656',
		},
		machineId: '', //洗车机id
	},
	mutations: {
		setScroll(state, data) {
			state.scroll = data
		},
		//首页切换
		setChangeIndex(state, data) {
			state.changeIndex = data
		},
		//爱车数量
		setCarNum(state, data) {
			state.carNum = data.carNum
		},
		setAddress(state, data) {
			state.city = data.city
			state.province = data.province
			state.district = data.district
			state.postalCode = data.postalCode
			state.lon = data.lon
			state.lat = data.lat
		},
		// 登录信息
		setModel(state, phoneModel) {
			state.model = phoneModel
		},
		//存储设备imei
		setImei(state, data) {
			state.imei = data
		},
		// 存储优惠券信息
		couponInfo(state, data) {
			state.couponInfo = data
		},
		// 存储tim用户信息
		timUserInfo(state, data) {
			state.timUserInfo = data
		},
		userinfo(state, data) {
			state.userinfo = data
		},
		currentLocation(state, data) {
			state.currentLocation = data
		},
		isSDKReady(state, data) {
			state.isSDKReady = data
		},
		massTempData(state, data) {
			state.massTempData = data
		},
		maintenanceOrderInfo(state, data) {
			state.maintenanceOrderInfo = data
		},
		maintenanceCategory(state, data) {
			state.maintenanceCategory = data
		},
		queueInfo(state, data) {
			state.queueInfo = data
		},
		maintenanceOrder(state, data) {
			state.maintenanceOrder = data
		},
		myLoveCar(state, data) {
			state.myLoveCar = data
		},
		purchaseChannel(state, data) {
			state.purchaseChannel = data
		},
		// 设置socket连接状态
		setConnectSocket(state, data) {
			state.isConnectSocket = data
		},
		setServiceNumber(state, {
			showNumber,
			number
		}) {
			state.serviceNumber.number = number
			state.serviceNumber.showNumber = showNumber

		},
		setMachineId(state, data) {
			state.machineId = data
		}
	},
	actions: {
		changeAddress({
			commit
		}, address) {
			commit('setAddress', address)
		},

		//处理车子数量
		changeCarNum({
			commit
		}, carNum) {
			commit('setCarNum', carNum)
		},
		couponInfo({
			commit
		}) {
			commit('couponInfo')
		},
		timUserInfo({
			commit
		}) {
			commit('timUserInfo')
		},
		userinfo({
			commit
		}) {
			commit('userinfo')
		},
		currentLocation({
			commit
		}) {
			commit('currentLocation')
		},
		isSDKReady({
			commit
		}) {
			commit('isSDKReady')
		},
		massTempData({
			commit
		}) {
			commit('massTempData')
		},
		maintenanceOrderInfo({
			commit
		}) {
			commit('maintenanceOrderInfo')
		},
		maintenanceCategory({
			commit
		}) {
			commit('maintenanceCategory')
		},
		queueInfo({
			commit
		}) {
			commit('queueInfo')
		},
		maintenanceOrder({
			commit
		}) {
			commit('maintenanceOrder')
		},
		changeIndexOrStore({
			commit
		}, changeIndex) {
			commit('setChangeIndex', changeIndex)
		},
		myLoveCar({
			commit
		}) {
			commit('myLoveCar')
		},
		purchaseChannel({
			commit
		}) {
			commit('purchaseChannel')
		},
	},
	getters: {
		//首页切换
		changeIndexOrStore(state) {
			return state.changeIndex
		},
		couponInfo(state) {
			return state.couponInfo
		},
		timUserInfo(state) {
			return state.timUserInfo
		},
		userinfo(state) {
			return state.userinfo
		},
		currentLocation(state) {
			return state.currentLocation
		},
		isSDKReady(state) {
			return state.isSDKReady
		},
		massTempData(state) {
			return state.massTempData
		},
		maintenanceOrderInfo(state) {
			return state.maintenanceOrderInfo
		},
		maintenanceCategory(state) {
			return state.maintenanceCategory
		},
		queueInfo(state) {
			return state.queueInfo
		},
		maintenanceOrder(state) {
			return state.maintenanceOrder
		},
		myLoveCar(state) {
			return state.myLoveCar
		},
		purchaseChannel(state) {
			return state.purchaseChannel
		},
		machineId(state) {
			return state.machineId
		}
	},
	modules: {
		poster,
		news
	},
})

export default store
